package com.sqx.modules.log.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.sqx.common.utils.Result;
import com.sqx.modules.log.dao.SysLogErrorDao;
import com.sqx.modules.log.entity.SysLogErrorEntity;
import com.sqx.modules.log.service.SysLogErrorService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

/**
 * 异常日志
 *
 * @author fang
 *
 */
@Service
public class SysLogErrorServiceImpl extends ServiceImpl<SysLogErrorDao, SysLogErrorEntity> implements SysLogErrorService {

    @Override
    public Result page(JSONObject params) {
        Integer pageNum = params.getInteger("pageNum");
        Integer pageSize = params.getInteger("pageSize");
        PageHelper.startPage(pageNum,pageSize);
        List<SysLogErrorEntity> sysLogErrorEntities = baseMapper.queryAll(params.getString("method"), params.getString("ip"), params.getString("uri"));
        PageInfo<SysLogErrorEntity> sysLogErrorEntityPageInfo = new PageInfo<>(sysLogErrorEntities);
        return Result.success().put("data",sysLogErrorEntityPageInfo);
    }

    @Override
    public List<SysLogErrorEntity> list(Map<String, Object> params) {
        List<SysLogErrorEntity> entityList = baseMapper.selectList(getWrapper(params));

        return entityList;
    }

    private QueryWrapper<SysLogErrorEntity> getWrapper(Map<String, Object> params){
        QueryWrapper<SysLogErrorEntity> wrapper = new QueryWrapper<>();
        return wrapper;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void insertSysLogError(SysLogErrorEntity entity) {
        baseMapper.insert(entity);
    }

}